<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="css/commodity.css"/>
		<link rel="stylesheet" type="text/css" href="css/pageSwitch.min.css"/>
		<!--<script src="js/jquery.min.js"></script>-->
		<script src="js/jquery-2.1.0.js"></script>
		<script src="js/indexjs.js"></script>

		<script>
			$(function(){

				
				function GetRequest() { 
					var url = location.search; //获取url中"?"符后的字串 
					var theRequest = new Object(); 
					if (url.indexOf("?") != -1) { 
						var str = url.substr(1); 
						strs = str.split("&"); 
						for(var i = 0; i < strs.length; i ++) { 
							theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); 
						} 
					} 
				return theRequest; 
				} 
				Request = GetRequest(); 
				var a,b;
				a = Request['goodsId']; 
				b = Request['userId']; 
				
				$.ajax("/fengwei/details/selectGoodsPic",{
					type:"get",
					data:{
						'goodsId':a
					},
					success:function(data){
						var dataObj = eval('('+data+')');
						console.log(dataObj);
						for(var i = 0;i<dataObj.length;i++){
							var arr = dataObj[i].fileUrl.split("\\");
							var src = arr[arr.length-2]+"/"+arr[arr.length-1];
							var img = document.getElementsByClassName('goods_img')[0];
							img.src = src;
						}
					},
					error:function(){

					}
				});


				$.ajax("/fengwei/details/selectGoods",{
					type:"get",
					data:{
						'goodsId':a
					},
					success:function(data){
						var dataObj = eval('('+data+')');
						console.log(dataObj);
						setData(dataObj);
					},
					error:function(){

					}
				});

				function setData(dataObj){

					var goodsName = dataObj.goodsName;
					var goodsPrice = dataObj.goodsPrice;
					var goodsUnit = dataObj.goodsUnit;
					var goodsIntroducts = dataObj.goodsIntroducts;
					var goodsSize = dataObj.goodsSize;

					var goods_name = document.getElementsByClassName("goods_name")[0];
					var goods_price = document.getElementsByClassName("goods_price")[0];
					var goods_introduce = document.getElementsByClassName("goods_introduce")[0];
					var total = document.getElementById("total");

					goods_name.innerHTML = goodsName;
					goods_price.innerHTML = goodsPrice+goodsUnit;
					goods_introduce.innerHTML = goodsIntroducts;
					total.innerHTML = goodsSize;

				}

				var right_button = $(".shop .right_button");
				right_button.click(function(){

					var inp = $("#inp").val();
					console.log(inp);
					$.ajax("/fengwei/details/addShopCart",{
						type:"post",
						data:{
							'goodsId':a,
							'goodsSize':inp
						},
						success:function(data){

							console.log(data);


						},
						error:function(){
							alert(0);
						}
					});
				});

				var left_button = $(".pay .left_button");
				left_button.click(function(){
					var inp = $("#inp").val();
					console.log(inp);
					$.ajax("/fengwei/shopping/payCart1",{
						type:"post",
						data:{
							'goodsId':a,
							'goodsSize':inp
						},
						success:function(data){

							console.log(data);
							if(data == "true"){
								window.location.href = "success.html?userId="+b+"";
							} else{
								window.location.href = "Home.html?userId="+b+"";
							}
						},
						error:function(){
							alert(0);
						}
					});
				})

				$.ajax("/fengwei/comment/showComment",{
					type:"get",
					data:{
						'goodsId':a
					},
					success:function(data){

						var dataObj = eval('('+data+')');
						console.log(dataObj);
						setComment(dataObj);

					},
					error:function(){
						alert(0);
					}
				});

				function setComment(dataObj){

					var goods_comment = document.getElementsByClassName("goods_comment")[0];

					if(dataObj.length==0){
						var newDiv = document.createElement("div");
						goods_comment.append(newDiv);
						newDiv.innerHTML = "<p>该商品暂时无评论</p>"
					} else if(dataObj.length == 1){

						var arr1 = dataObj[0].fileUrl.split("\\");
						var src1 = arr1[arr1.length-2]+"/"+arr1[arr1.length-1];

						var newDiv = document.createElement("div");
						newDiv.id = "user_box";
						goods_comment.append(newDiv);
						newDiv.innerHTML = "<div class='user'>"+
						        "<img class='user_img' src="+src1+"/><span id='user_name'>"+dataObj[0].userNikename+"</span>"+
								"</div> " +
								"<div class='user_comment'>"+
								"<p class='comment_con'>"+dataObj[0].Comments+"</p>"+
								"</div>"
					} else {

						for(var i = 0;i<2;i++){

							var arr = dataObj[i].fileUrl.split("\\");
							var src = arr[arr.length-2]+"/"+arr[arr.length-1];

							var newDiv = document.createElement("div");
							newDiv.id = "user_box";
							goods_comment.append(newDiv);
							newDiv.innerHTML = "<div class='user'>"+
									"<img class='user_img' src="+src+"/><span id='user_name'>"+dataObj[i].userNikename+"</span>"+
									"</div> " +
									"<div class='user_comment'>"+
									"<p class='comment_con'>"+dataObj[i].Comments+"</p>"+
									"</div>"
						}
					}


				}


			});
		</script>

	</head>
	
	<body>
		<div id="commodity_head">      <!--头部 -->
			 <a href=”#” onClick="javascript :history.back(-1);"> <img class="img_return" src="img/return.png"/> </a>
			 <span class="head_details">商品详情</span>
		</div> <br />
		<!--end-->
		
		<!--<div id="container">   &lt;!&ndash; 轮播图&ndash;&gt;-->
		<!--&lt;!&ndash;<div class="sections">&ndash;&gt;-->
			<!--&lt;!&ndash;<div class="section" id="section0"></div>&ndash;&gt;-->
			<!--&lt;!&ndash;<div class="section" id="section1"></div>&ndash;&gt;-->
			<!--&lt;!&ndash;<div class="section" id="section2"></div>&ndash;&gt;-->
			<!--&lt;!&ndash;<div class="section" id="section3"></div>&ndash;&gt;-->
		<!--&lt;!&ndash;</div>&ndash;&gt;-->
	<!--</div>-->
		<div id="commodity_img">    <!--商品图片 -->
			<img class="goods_img" src="img/02.jpg"/>
		</div>
		<!--end-->
		
		<div id="details">  <!--商品详情 -->
			<div class="goods_name">
				皮皮虾
			</div>
			<div class="goods_price">
				￥100/kg
			</div>
			<div class="goods_introduce">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;虾蛄是一种营养丰富、汁鲜肉嫩的海味食品。
				其肉质含水分较多，肉味鲜甜嫩滑，淡而柔软，并且有一种特殊诱人的鲜味。
				每年春季是其产卵的季节，此时食用为最佳。肥壮的虾蛄脑部满是膏脂，肉质十分鲜嫩，味美可口，
				可惜壳多肉少。
			</div>
			<br />
			
		</div>
		<!--end -->
		
		<div id="commodity_num">
			选择商品数量：<input class="sdddq" id="inp"  />
			<span style="position: absolute;top: 20px;left: 170px;font-size: 15px;">库存：<span id="total" style="color: red"></span></span>
		</div>
		
		<div id="comment">   <!--商品评论 -->
			<div class="goods_comment">
				<h3 style="font-size: 16px;margin-left: 5%;margin-bottom: 10px;">宝贝评价</h3>


			</div>
		</div>
		<!--end -->
		
		<div id="commodity_footer">
			<a class="pay" href="javascript:"><div class="left_button">
				立即付款
			</div></a>
			<a class="shop" href="javascript:"><div class="right_button">
				加入购物车
			</div></a>
		</div>
	
	
<script src="js/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="js/pageSwitch.min.js"></script>
<script>
	$("#container").PageSwitch({
		direction:'horizontal',
		easing:'ease-in',
		duration:1000,
		autoPlay:true,
		loop:'false'
	});
</script>
	
	
	</body>
</html>
